package graph.group.zhangtao.guider.homepage.fragments;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.ListFragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import graph.group.zhangtao.guider.R;
import graph.group.zhangtao.guider.homepage.activities.ToolBarX;
import graph.group.zhangtao.guider.homepage.adapters.SpotItemAdapter;
import graph.group.zhangtao.guider.homepage.content.SpotItem;

/**
 * Created by T5 on 2016/6/16.
 */
public class HomePageFragment extends ListFragment {

    //声明初始化的toolbar 视图和活动
    private ListView listView;
    private Toolbar toolbar;
    private ToolBarX mToolbar;
    private FragmentActivity activity;
    private View view;
    private List<SpotItem> spotItems = new ArrayList<>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    //初始化视图活动和toolbar
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fg_homepage, container, false);
        activity = getActivity();
        initToolbar();
        initSpots();
        SpotItemAdapter adapter = new SpotItemAdapter(getContext(),R.layout.spot_item,R.id.tv_spot_name, spotItems);
        setListAdapter(adapter);
        return view;
    }

    //初始化toolbar函数
    private void initToolbar() {
        toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
        toolbar.setVisibility(View.VISIBLE);
        mToolbar = new ToolBarX(toolbar, (AppCompatActivity) activity);
        mToolbar.setDisplayHomeAsUpEnabled(false).setTitle("景点推荐").setSubTitle("");
    }

    //初始化景点列表
    private void initSpots(){

        SpotItem spot1 = new SpotItem(
                getString(R.string.spotname1),
                getString(R.string.spotdesc1),
                R.drawable.spot1
        );
        spotItems.add(spot1);

        SpotItem spot2 = new SpotItem(
                getString(R.string.spotname2),
                getString(R.string.spotdesc2),
                R.drawable.spot2
        );
        spotItems.add(spot2);

        SpotItem spot3 = new SpotItem(
                getString(R.string.spotname3),
                getString(R.string.spotdesc3),
                R.drawable.spot3
        );
        spotItems.add(spot3);

        SpotItem spot4 = new SpotItem(
                getString(R.string.spotname4),
                getString(R.string.spotdesc4),
                R.drawable.spot4
        );
        spotItems.add(spot4);

        SpotItem spot5 = new SpotItem(
                getString(R.string.spotname5),
                getString(R.string.spotdesc5),
                R.drawable.spot5
        );
        spotItems.add(spot5);

    }




}
